package com.school.controller.user;

import com.school.model.Student;
import com.school.model.User;
import com.school.service.StudentService;
import com.school.service.UserService;
import com.school.service.impl.StudentServiceImpl;
import com.school.service.impl.UserServiceImpl;
import com.school.util.ResponseJsonUtil;
import com.school.vo.R;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;

@WebServlet("/user/update")
public class UpdateController extends HttpServlet {
    UserService service = new UserServiceImpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 插入 数据
        String id = req.getParameter("id");// id
        if (id == null) {
            // json格式传递到前端
            ResponseJsonUtil.write(resp, R.err("id字段必须"));
            return;
        }
        Integer idd = Integer.valueOf(id);
        User user = new User();
        user.setNickname(req.getParameter("nickname"));
        user.setUsername(req.getParameter("username"));
        user.setPassword(req.getParameter("password"));

        user.setId(idd);

        // 调用Service中的方法
        service.update(user);

        // json格式传递到前端
        ResponseJsonUtil.write(resp, R.ok());
    }
}
